package edu.hubu.model;

/**
 * @author moonlan
 * date 2020/11/13 19:40
 */

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import edu.hubu.annotations.FilterField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import net.moon.annotation.FieldIgnore;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedDate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@SuppressWarnings(value = "unused")
@Entity
@Table(name = "teacher")
//逻辑删除注解，删除sql变成了update
@SQLDelete(sql = "update teacher set teacher_is_deleted = true where user_sid = ?")
//where条件带上了逻辑删除条件
@Where(clause = "teacher_is_deleted = false")
@ApiModel("老师类")
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "fieldHandler"})
public class Teacher extends User {
    @Id
    @Column(name = "user_sid")
    @ApiModelProperty(value = "用户工号", position = 1)
    private String userSid;

    @Column(name = "user_name")
    @ApiModelProperty(value = "用户姓名", position = 2)
    protected String userName;

    @Column(name = "user_password")
    @ApiModelProperty(value = "用户密码", position = 3)
    @FieldIgnore
    protected String userPassword;

    @Column(name = "user_telephone_number")
    @ApiModelProperty(value = "用户电话号码", position = 8)
    @FieldIgnore
    protected String userTelephoneNumber;

    @Column(name = "user_effective_date")
    @ApiModelProperty(value = "用户帐号生效时间", position = 9)
    @CreatedDate
    @FieldIgnore
    protected Date userEffectiveDate;

    @Column(name = "user_expiry_date")
    @ApiModelProperty(value = "用户帐号失效时间", position = 10)
    @FieldIgnore
    protected Date userExpiryDate;

    @Column(name = "user_api_key")
    @ApiModelProperty(value = "用户Apikey", position = 11)
    @FieldIgnore
    protected String userApiKey;

    @Column(name = "user_api_key_expiry_date")
    @ApiModelProperty(value = "用户Apikey失效时间", position = 12)
    @FieldIgnore
    protected Date userApiKeyExpiryDate;

    @Column(name = "user_photo_url")
    @ApiModelProperty(value = "用户头像url", position = 13)
    protected String userPhotoUrl;

    @Column(name = "teacher_is_forbidden")
    @ApiModelProperty(value = "老师是否被禁用", position = 14)
    @FieldIgnore
    private boolean teacherIsForbidden = false;

    @Column(name = "teacher_is_deleted")
    @ApiModelProperty(value = "老师是否被删除", position = 15)
    @FieldIgnore
    private boolean teacherIsDeleted = false;

    @Column(name = "user_is_forbidden")
    @ApiModelProperty(value = "用户是否被禁用", position = 14)
    private boolean userIsForbidden = false;

    @Column(name = "user_is_deleted")
    @ApiModelProperty(value = "用户是否被删除", position = 15)
    private boolean userIsDeleted = false;

    @ManyToOne(targetEntity = Role.class, cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @JoinColumn(name = "user_role_id", referencedColumnName = "role_id")
    protected Role role;

    @Override
    public Teacher setUserSid(String userSid) {
        this.userSid = userSid;
        return this;
    }

    @Override
    public Teacher setUserName(String userName) {
        this.userName = userName;
        return this;
    }

    @Override
    public Teacher setUserPassword(String userPassword) {
        this.userPassword = userPassword;
        return this;
    }

    @Override
    public Teacher setUserTelephoneNumber(String userTelephoneNumber) {
        this.userTelephoneNumber = userTelephoneNumber;
        return this;
    }

    @Override
    public Teacher setUserEffectiveDate(Date userEffectiveDate) {
        this.userEffectiveDate = userEffectiveDate;
        return this;
    }

    @Override
    public Teacher setUserExpiryDate(Date userExpiryDate) {
        this.userExpiryDate = userExpiryDate;
        return this;
    }

    @Override
    public Teacher setUserApiKey(String userApiKey) {
        this.userApiKey = userApiKey;
        return this;
    }

    @Override
    public Teacher setUserApiKeyExpiryDate(Date userApiKeyExpiryDate) {
        this.userApiKeyExpiryDate = userApiKeyExpiryDate;
        return this;
    }

    @Override
    public Teacher setUserPhotoUrl(String userPhotoUrl) {
        this.userPhotoUrl = userPhotoUrl;
        return this;
    }

    @Override
    public boolean isUserIsForbidden() {
        return userIsForbidden;
    }

    @Override
    public Teacher setUserIsForbidden(boolean userIsForbidden) {
        this.userIsForbidden = userIsForbidden;
        return this;
    }

    @Override
    public boolean isUserIsDeleted() {
        return userIsDeleted;
    }

    @Override
    public Teacher setUserIsDeleted(boolean userIsDeleted) {
        this.userIsDeleted = userIsDeleted;
        return this;
    }

    @Override
    public Role getRole() {
        return role;
    }

    @Override
    public Teacher setRole(Role role) {
        this.role = role;
        return this;
    }

    @ManyToOne(targetEntity = Institution.class, cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @JoinColumn(name = "teacher_institution_id", referencedColumnName = "institution_id")
    @ApiModelProperty(value = "老师学院", position = 7)
    private Institution institution;

    @ApiModelProperty(value = "老师专业", position = 6)
    @ManyToOne(targetEntity = Major.class, cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @JoinColumn(name = "teacher_major_id", referencedColumnName = "major_id")
    private Major major;

    @ManyToMany(mappedBy = "teachers", cascade = {CascadeType.REFRESH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private List<TeacherCourse> teacherCourses = new ArrayList<>();

    @ManyToMany(mappedBy = "teachers", fetch = FetchType.LAZY)
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private List<StudentCourse> studentCourses = new ArrayList<>();

    public Teacher(String userSid, String userName, String userPassword, String userTelephoneNumber, Date userEffectiveDate, Date userExpiryDate, String userApiKey, Date userApiKeyExpiryDate, String userPhotoUrl, boolean teacherIsForbidden, boolean teacherIsDeleted, Institution institution, Major major, List<TeacherCourse> teacherCourses, List<StudentCourse> studentCourses) {
        this.userSid = userSid;
        this.userName = userName;
        this.userPassword = userPassword;
        this.userTelephoneNumber = userTelephoneNumber;
        this.userEffectiveDate = userEffectiveDate;
        this.userExpiryDate = userExpiryDate;
        this.userApiKey = userApiKey;
        this.userApiKeyExpiryDate = userApiKeyExpiryDate;
        this.userPhotoUrl = userPhotoUrl;
        this.teacherIsForbidden = teacherIsForbidden;
        this.teacherIsDeleted = teacherIsDeleted;
        this.institution = institution;
        this.major = major;
        this.teacherCourses = teacherCourses;
        this.studentCourses = studentCourses;
    }

    public Teacher() {
    }

    public String getUserSid() {
        return this.userSid;
    }

    public String getUserName() {
        return this.userName;
    }

    public String getUserPassword() {
        return this.userPassword;
    }

    public String getUserTelephoneNumber() {
        return this.userTelephoneNumber;
    }

    public Date getUserEffectiveDate() {
        return this.userEffectiveDate;
    }

    public Date getUserExpiryDate() {
        return this.userExpiryDate;
    }

    public String getUserApiKey() {
        return this.userApiKey;
    }

    public Date getUserApiKeyExpiryDate() {
        return this.userApiKeyExpiryDate;
    }

    public String getUserPhotoUrl() {
        return this.userPhotoUrl;
    }

    public boolean isTeacherIsForbidden() {
        return this.teacherIsForbidden;
    }

    public boolean isTeacherIsDeleted() {
        return this.teacherIsDeleted;
    }

    public Institution getInstitution() {
        return this.institution;
    }

    public Major getMajor() {
        return this.major;
    }

    public List<TeacherCourse> getTeacherCourses() {
        return this.teacherCourses;
    }

    public List<StudentCourse> getStudentCourses() {
        return this.studentCourses;
    }

    public void setTeacherIsForbidden(boolean teacherIsForbidden) {
        this.teacherIsForbidden = teacherIsForbidden;
    }

    public void setTeacherIsDeleted(boolean teacherIsDeleted) {
        this.teacherIsDeleted = teacherIsDeleted;
    }

    public void setInstitution(Institution institution) {
        this.institution = institution;
    }

    public void setMajor(Major major) {
        this.major = major;
    }

    public void setTeacherCourses(List<TeacherCourse> teacherCourses) {
        this.teacherCourses = teacherCourses;
    }

    public void setStudentCourses(List<StudentCourse> studentCourses) {
        this.studentCourses = studentCourses;
    }
}
